var TSUI;
(function (TSUI) {
    TSUI.getType = function (x) {
        return Object.prototype.toString.call(x);
    };

    TSUI.isNumber = function (x) {
        return TSUI.getType(x) === "[object Number]";
    };

    TSUI.isString = function (x) {
        return TSUI.getType(x) === "[object String]";
    };

    TSUI.isDate = function (x) {
        return TSUI.getType(x) === "[object Date]";
    };

    TSUI.isFunction = function (x) {
        return TSUI.getType(x) === "[object Function]";
    };

    TSUI.isArray = function (x) {
        return TSUI.getType(x) === "[object Array]";
    };

    TSUI.StopEvent = function (jqEvent) {
        if (!jqEvent.keyCode || jqEvent.keyCode === 13 || jqEvent.keyCode === 8 || (jqEvent.keyCode >= 17 && jqEvent.keyCode <= 90) || (jqEvent.keyCode >= 96 && jqEvent.keyCode <= 111) || (jqEvent.keyCode >= 186 && jqEvent.keyCode <= 222)) {
            jqEvent.stopPropagation();
            jqEvent.stopImmediatePropagation();
            jqEvent.preventDefault();
        }
    };

    TSUI.GetPosition = function (control) {
        var element = control.AnimationElement();

        var startPosObj = {
            top: control.Top(),
            left: control.Left()
        };
        var startPos = {
            top: 0,
            left: 0
        };
        if (startPosObj.left.Units === "%") {
            var parentWidth = element.parent().width();
            var leftPerc = startPosObj.left.Value;
            startPos.left = (leftPerc / 100) * parentWidth;
        } else {
            startPos.left = startPosObj.left.Value;
        }
        if (startPosObj.top.Units === "%") {
            var parentHeight = element.parent().height();
            var topPerc = startPosObj.top.Value;
            startPos.top = (topPerc / 100) * parentHeight;
        } else {
            startPos.top = startPosObj.top.Value;
        }

        return startPos;
    };

    TSUI.GetSize = function (control) {
        var element = control.AnimationElement();

        var startPosObj = {
            width: control.Width(),
            height: control.Height()
        };
        var startPos = {
            width: 0,
            height: 0
        };
        if (startPosObj.width.Units === "%") {
            var parentWidth = element.parent().width();
            var leftPerc = startPosObj.width.Value;
            startPos.width = (leftPerc / 100) * parentWidth;
        } else {
            startPos.width = startPosObj.width.Value;
        }
        if (startPosObj.height.Units === "%") {
            var parentHeight = element.parent().height();
            var topPerc = startPosObj.height.Value;
            startPos.height = (topPerc / 100) * parentHeight;
        } else {
            startPos.height = startPosObj.height.Value;
        }

        return startPos;
    };

    TSUI.OpenInNewWindow = function (url) {
        var win = window.open(url, '_blank');
        win.focus();
    };

    TSUI.roundTo = function (x, multiple) {
        var neg = x < 0 ? -1 : 1;
        x = Math.abs(x);
        var resto = x % multiple;
        if (resto <= (multiple / 2)) {
            return (x - resto) * neg;
        } else {
            return (x + multiple - resto) * neg;
        }
    };

    TSUI.standardiseEvent = function (jqEvent) {
        if (jqEvent) {
            if (jqEvent.originalEvent) {
                if (jqEvent.originalEvent.touches) {
                    if (jqEvent.originalEvent.touches.length > 0) {
                        jqEvent.pageX = jqEvent.originalEvent.touches[0].pageX;
                        jqEvent.pageY = jqEvent.originalEvent.touches[0].pageY;
                    }
                }
            }
        }
        return jqEvent;
    };
})(TSUI || (TSUI = {}));
